/*
 * Copyright (c) Jan Šlahora (${USER}) - 2011.
 * Created in IntelliJ IDEA 10.5
 */

import Jama.EigenvalueDecomposition;
import MW.MW;
import com.sun.swing.internal.plaf.synth.resources.synth_es;
import stuff.FileManager;

import javax.swing.*;
import java.awt.*;
import java.util.Map;

public class SVLA {
  static String settFile = "sett.conf";

  public static void createWindow(MW mainWindow) {
    Map<String, String> sett = FileManager.readFile(settFile);

    setSize(sett, mainWindow);
    setLocation(sett, mainWindow);
  }

  public static void setSize(Map<String, String> sett, MW mainWindow) {
    if (sett.containsKey("Width") && sett.containsKey("Height")) {

      if (Integer.parseInt(sett.get("Width")) > 0 &&
          Integer.parseInt(sett.get("Height")) > 0 &&
          Integer.parseInt(sett.get("Width")) < Toolkit.getDefaultToolkit().getScreenSize().getWidth() &&
          Integer.parseInt(sett.get("Height")) < Toolkit.getDefaultToolkit().getScreenSize().getHeight())
      {
        mainWindow.setSize(
            Integer.parseInt(sett.get("Width")),
            Integer.parseInt(sett.get("Height")));
      }
    }
  }

  public static void setLocation(Map<String, String> sett, MW mainWindow) {
    if (sett.containsKey("Top") && sett.containsKey("Left")) {
      if (Double.parseDouble(sett.get("Top")) < Toolkit.getDefaultToolkit().getScreenSize().getWidth() &&
          Double.parseDouble(sett.get("Left")) < Toolkit.getDefaultToolkit().getScreenSize().getHeight()) {
        mainWindow.setLocation(
            (int) Double.parseDouble(sett.get("Left")),
            (int) Double.parseDouble(sett.get("Top"))
        );
      }
    }
  }



  public static void main(String[] args) {
    //.. vytvoříme okno
    MW mainWindow = new MW();

    //.. Nastavení
   createWindow(mainWindow);

    //... Zobrazení okna
    mainWindow.setVisible(true);

  }
}
